let mysql=require('mysql');

let db=mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'root',
    database:'tiantianpeiwan',
    timezone:'08:00'
});


var OrderModule={
    // 加载获取页面
    getorder:function (JD_uid,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON b.U_co=c.U_co 
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_uid="${JD_uid}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 待支付按钮
    dzforder:function (JD_uid,JD_puon,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON b.U_co=c.U_co 
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_uid="${JD_uid}" AND a.JD_puon="${JD_puon}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 进行中
    jxzorder:function (JD_uid,JD_puon,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON b.U_co=c.U_co 
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_uid="${JD_uid}" AND a.JD_puon="${JD_puon}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 已完成
    ywcorder:function (JD_uid,JD_puon1,JD_puon2,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON b.U_co=c.U_co 
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_uid="${JD_uid}" AND a.JD_puon="${JD_puon1}" OR a.JD_puon="${JD_puon2}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 已取消支付
    yqxzforder:function (JD_uid,JD_puon,JD_zfdatetimes,JD_co,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_zfdatetimes="${JD_zfdatetimes}"
WHERE JD_uid="${JD_uid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
   // 已取消接单
    yqxjdorder:function (JD_uid,JD_puon,JD_jddatetimes,JD_co,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_jddatetimes="${JD_jddatetimes}"
WHERE JD_uid="${JD_uid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
   // 点击评价
        //修改订单状态（插入评论）
    pjforder:function (JD_uid,JD_puon,JD_pldatetimes,JD_co,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_pldatetimes="${JD_pldatetimes}"
WHERE JD_uid="${JD_uid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data) {
            fn(err,data);
        })
    },
    xiao:function (JD_pldatetimes,JD_co,EV_sec,EV_sorce,fn) {

        let sql2=`INSERT INTO p_evaluate VALUES(NULL,"${JD_pldatetimes}","${EV_sec}","${JD_co}","${EV_sorce}",0)`;
            db.query(sql2,function (err,data){
                fn(err,data)
        })
    },
    // 修改评价
    xgpjorder:function (EV_sorce,EV_sec,EV_datetimes,JD_co,fn) {
        let sql=`UPDATE p_evaluate SET EV_sorce="${EV_sorce}",EV_sec="${EV_sec}",EV_datetimes="${EV_datetimes}"
         WHERE JD_co="${JD_co}"`;
            db.query(sql,function (err,data){
                fn(err,data)
        })
    },
    // 查看评论
    splorder:function (JD_co,fn) {
        let sql=`SELECT * FROM p_evaluate WHERE JD_co="${JD_co}"`;
            db.query(sql,function (err,data){
                fn(err,data)
        })
    },
    // 完成订单（结束订单，但是还没有评价）
    wcorder:function (JD_uid,JD_puon,JD_wcdatetimes,JD_co,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_wcdatetimes="${JD_wcdatetimes}"
WHERE JD_uid="${JD_uid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 超时取消
    cszforder:function (JD_uid,JD_puon,JD_zfdatetimes,JD_co,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_zfdatetimes="${JD_zfdatetimes}"
WHERE JD_uid="${JD_uid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
// ----------------------------------------陪玩订单------------------------
    getplayorder:function (JD_puid,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON a.U_co=c.U_co  
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_puid="${JD_puid}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 进行中
    jxzplayorder:function (JD_puid,JD_puon,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON a.U_co=c.U_co  
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_puid="${JD_puid}" AND a.JD_puon="${JD_puon}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 已完成
    ywcplayorder:function (JD_puid,JD_puon1,JD_puon2,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON a.U_co=c.U_co 
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_puid="${JD_puid}" AND a.JD_puon="${JD_puon1}" OR a.JD_puon="${JD_puon2}"`;

        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 查看评论
    splplayorder:function (JD_co,fn) {
        let sql=`SELECT * FROM p_evaluate WHERE JD_co="${JD_co}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    // 接收订单
    okplayorder:function (JD_co,JD_puon,JD_jddatetimes,JD_jxdatetimes,JD_puid,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_jddatetimes="${JD_jddatetimes}",JD_jxdatetimes="${JD_jxdatetimes}"
WHERE JD_puid="${JD_puid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    // 拒绝订单
    jujueplayorder:function (JD_co,JD_puon,JD_jddatetimes,JD_puid,fn) {
        let sql=`UPDATE p_jdtable SET JD_puon="${JD_puon}", JD_jddatetimes="${JD_jddatetimes}"
WHERE JD_puid="${JD_puid}" AND JD_co="${JD_co}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    //查询搜索
    queryoplay:function (JD_puid,U_falsename,fn) {
        let sql=`SELECT *FROM p_jdtable a 
LEFT JOIN p_playuser b ON a.JD_co=b.JD_co 
LEFT JOIN p_user c ON a.U_co=c.U_co 
LEFT JOIN p_game d ON b.G_id=d.G_id
WHERE a.JD_puid="${JD_puid}" AND c.U_falsename LIKE '%${U_falsename}%'`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },

// -----------------------------------------关注------------------------
    // 页面加载
    getfollow:function (FO_uid,fn) {
        let sql=`SELECT *FROM p_follow a 
LEFT JOIN p_user b ON a.U_co=b.U_co 
WHERE FO_uid="${FO_uid}"`;
        db.query(sql,function (err,data) {
            fn(err,data)
        })
    },
    // 确定单个取消订单
        // 查询关注的人id
    dgqxfollow:function (U_photo,fn) {
        let sql=`SELECT U_id FROM p_user WHERE U_photo="${U_photo}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    dgqxfollow2:function (FO_uid,FO_puid,fn) {
        let sql=`DELETE FROM p_follow WHERE FO_uid="${FO_uid}" AND FO_puid="${FO_puid}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    //确定全部取消订单
        // 查询关注的人id
    qbqxfollow:function (FO_uid,fn) {
        let sql=`DELETE FROM p_follow WHERE FO_uid="${FO_uid}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },

// ----------------------------交易管理----------------------------------
    // 全选
    getbusiness:function (JD_uid,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE JD_puid="${JD_uid}" OR JD_uid="${JD_uid}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    // 收入塞选
    sybusiness:function (JD_uid,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE JD_puid="${JD_uid}" OR JD_uid="${JD_uid}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    // 支出筛选
    zcbusiness:function (JD_uid,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE JD_puid="${JD_uid}" OR JD_uid="${JD_uid}"`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    // 时间筛选
    alldatebusiness:function (JD_uid,begingtime,endtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND ((JD_zfdatetimes>="${begingtime}" AND JD_zfdatetimes<="${endtime}") 
AND (JD_jddatetimes>="${begingtime}" AND JD_jddatetimes<="${endtime}"))`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    srdatebusiness:function (JD_uid,begingtime,endtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND ((JD_zfdatetimes>="${begingtime}" AND JD_zfdatetimes<="${endtime}") 
AND (JD_jddatetimes>="${begingtime}" AND JD_jddatetimes<="${endtime}"))`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    zcdatebusiness:function (JD_uid,begingtime,endtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND ((JD_zfdatetimes>="${begingtime}" AND JD_zfdatetimes<="${endtime}") 
AND (JD_jddatetimes>="${begingtime}" AND JD_jddatetimes<="${endtime}"))`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },

    alldatebusiness1:function (JD_uid,begingtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND (JD_zfdatetimes>="${begingtime}" AND JD_jddatetimes>="${begingtime}")`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    srdatebusiness1:function (JD_uid,begingtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND (JD_zfdatetimes>="${begingtime}" AND JD_jddatetimes>="${begingtime}")`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    zcdatebusiness1:function (JD_uid,begingtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND (JD_zfdatetimes>="${begingtime}" AND JD_jddatetimes>="${begingtime}")`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },

    alldatebusiness2:function (JD_uid,endtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND (JD_zfdatetimes<="${endtime}" AND JD_jddatetimes<="${endtime}")`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    srdatebusiness2:function (JD_uid,endtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND (JD_zfdatetimes<="${endtime}" AND JD_jddatetimes<="${endtime}")`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },
    zcdatebusiness2:function (JD_uid,endtime,fn) {
        let sql=`SELECT a.JD_co DD,JD_uid YH,JD_puid PW,JD_zfdatetimes ZFDATA,JD_jddatetimes JDDATA,JD_money MONEY,JD_puon ZT FROM p_consumption a 
LEFT JOIN p_jdtable b ON a.JD_co=b.JD_co
WHERE (JD_puid="${JD_uid}" OR JD_uid="${JD_uid}")
AND (JD_zfdatetimes<="${endtime}" AND JD_jddatetimes<="${endtime}")`;
        db.query(sql,function (err,data){
            fn(err,data)
        })
    },


    // zuce:function (user,fn) {
    //     let sql=`select * from t——user where user="${user}"`;
    //
    //     db.query(sql,function (err,data) {
    //         fn(err,data)
    //     })
    // },
    // add:function (user,pass,fn) {
    //     let sql=`insert into t——user values(null,"${user}","${pass}")`;
    //     db.query(sql,function (err,data) {
    //         fn(err,data)
    //     })
    // }
};

module.exports=OrderModule;